<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>制作5个嵌套DIV</title>
		<style type="text/css">
			#div1
			{
				width: 500px;
				height: 500px;
				background-color: red;
				float: left;
				text-align: center;
			}
			#div2
			{
				width: 400px;
				height: 400px;
				background-color: blue;	
				float: left;
				margin-right: 50px;
				margin-left: 50px;
				margin-top: 30px;
			}
			#div3
			{
				width: 300px;
				height: 300px;
				background-color: green;
				float: left;
				margin-right: 50px;
				margin-left: 50px;
				margin-top: 30px;
				
			}
			#div4
			{
				width: 200px;
				height: 200px;
				background-color: yellow;
				float: left;
				margin-right: 50px;
				margin-left: 50px;
				margin-top: 30px;
				
			}
			#div5
			{
				width: 100px;
				height: 100px;
				background-color: deeppink;
				float: left;
				margin-right: 50px;
				margin-left: 50px;
				margin-top:30px;
			}d
		</style>
	</head>
	<body>
		<div id="div1" >
			第一个div
			<div id="div2">
				<span>第二个div</span>
				<div id="div3">
					<span>第三个div</span>
					<div id="div4" >
						<span>第四个div</span>
						<div id="div5" >
							<span>第五个div</span>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript">
			
			console.log("4级父元素为"+document.getElementById('div5').parentElement.innerHTML);
			console.log("3级父元素为"+document.getElementById('div5').parentElement.parentElement.innerHTML);
			console.log("2级父元素为"+document.getElementById('div5').parentElement.parentElement.parentElement.innerHTML);
			console.log("1级父元素为"+document.getElementById('div5').parentElement.parentElement.parentElement.parentElement.innerHTML);
			console.log('-----------------------------------------------')
			console.log("4级父节点为"+document.getElementById('div5').parentNode.innerHTML);
			console.log("4级父节点为"+document.getElementById('div5').parentNode.parentNode.innerHTML);
			console.log("4级父节点为"+document.getElementById('div5').parentNode.parentNode.parentNode.innerHTML);
			console.log("4级父节点为"+document.getElementById('div5').parentNode.parentNode.parentNode.parentNode.innerHTML);
			console.log('-----------------------------------------------')
			console.log("4级子元素为"+document.getElementById('div4').innerHTML);
			console.log("3级子元素为"+document.getElementById('div3').innerHTML);
			console.log("2级子元素为"+document.getElementById('div2').innerHTML);
			console.log("1级子元素为"+document.getElementById('div1').innerHTML);
			
			
			
	</script>
</html>
